#!/bin/bash
echo "use: fromapk toapk prefix user pkgname"
if [ "$5" == "" ]; then
	exit 1
fi
#exit 1
source /etc/profile
LOG_FOLDER=`date +'%Y%m%d'`
#LOG_ROOT=/var/log/riskman/$LOG_FOLDER
LOG_ROOT=/datastorage/riskman/$LOG_FOLDER
LOG_FILENAME=$3
mkdir -p $LOG_ROOT 2>> /dev/null

outdir=${2%/*}
if [ "$outdir" != "$2" ]; then
	mkdir -p $outdir 2> /dev/null
fi

declare -l luser=$4

cat user_config.txt | while read user pkg agid ip cver javaver t1_t2
do
	if [ "$pkg" == "$5" -a "$user" == "<$luser>" ] || [ "$user" == "$luser" ]; then
		if [ ! -f "/tmp/local_test_risk" ];then
			. pack.sh $1 ${agid} ${ip} ${cver} ${javaver} $2 $3 $5 ${t1_t2} >> "$LOG_ROOT/output_$LOG_FILENAME.log" 2>> "$LOG_ROOT/error_$LOG_FILENAME.log"
		else
			. pack.sh $1 ${agid} ${ip} ${cver} ${javaver} $2 $3 $5 ${t1_t2}
		fi
		break
	fi
done


if [ ! -f $2 ]; then
	echo "fail $@" >> $LOG_ROOT/fail.log
	exit 1
fi
exit 0

